﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Tile_Engine;

namespace AGrandVenture
{
    public class Resource
    {
        private Texture2D resourceTexture;
        private Rectangle initialFrame;
        private Vector2 worldLocation;
        private string name;
        private int value;
        private bool enabled;
        private Color tintColour;

        public bool Enabled
        {
            get { return enabled; }
            set { enabled = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public int Value
        {
            get { return value; }
            set { this.value = value; }
        }

        public Vector2 WorldLocation
        {
            get { return worldLocation; }
            set { worldLocation = value; }
        }

        public Color TintColour
        {
            get { return tintColour; }
            set { tintColour = value; }
        }

        public Rectangle WorldRectangle
        {
            get { return new Rectangle((int)worldLocation.X, (int)worldLocation.Y, initialFrame.Width, initialFrame.Height); }
        }

        public Resource(string name, int value, int cellX, int cellY, Texture2D texture, Rectangle initialFrame, Color colour)
        {
            Name = name;
            Value = value;
            resourceTexture = texture;
            this.initialFrame = initialFrame;
            worldLocation.X = TileMap.TileWidth * cellX;
            worldLocation.Y = TileMap.TileHeight * cellY;
            tintColour = colour;
            Enabled = true;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            if (!enabled)
                return;

            SpriteEffects effect = SpriteEffects.None;

            spriteBatch.Draw(
                resourceTexture,
                Camera.WorldToScreen(WorldRectangle),
                initialFrame,
                tintColour,
                0.0f,
                Vector2.Zero,
                effect,
                0.85f);

        }
    }
}
